Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: datalog foreign function interface prototype #228

Draft
wants to merge 7 commits into
base: v5
Choose a base branch
from
Draft

wip: datalog foreign function interface prototype #228

wants to merge 7 commits into from

Conversation

divarvel
Copy link
Collaborator

@divarvel divarvel commented Oct 2, 2024

This allows using external functions in datalog.

This makes it easy to provide custom logic without extending the spec for every use-case, at the expense of portability: behaviour is no longer guaranteed to be consistent cross languages, and some languages won’t be able to support it at all (for instance JS as of now).

Open questions:

  • should function names be interned as well? they are currently not

Code coverage should be improved by adding samples

Copy link

codspeed-hq bot commented Oct 2, 2024

CodSpeed Performance Report

Merging #228 will not alter performance

Comparing ffi (99c0718) with v5 (e59f41d)

Summary

✅ 12 untouched benchmarks

Copy link

codecov bot commented Oct 2, 2024

Codecov Report

Attention: Patch coverage is 75.30120% with 82 lines in your changes missing coverage. Please review.

Project coverage is 69.58%. Comparing base (3930767) to head (99c0718).
Report is 1 commits behind head on v5.

Files with missing lines Patch % Lines
biscuit-parser/src/builder.rs 0.00% 34 Missing ⚠️
biscuit-auth/src/token/builder.rs 86.76% 18 Missing ⚠️
biscuit-auth/src/format/convert.rs 74.13% 15 Missing ⚠️
biscuit-auth/src/token/authorizer.rs 50.00% 8 Missing ⚠️
biscuit-auth/src/datalog/expression.rs 90.90% 4 Missing ⚠️
biscuit-auth/examples/testcases.rs 92.85% 2 Missing ⚠️
biscuit-auth/src/token/authorizer/snapshot.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##               v5     #228      +/-   ##
==========================================
+ Coverage   69.03%   69.58%   +0.54%     
==========================================
  Files          25       25              
  Lines        5926     6154     +228     
==========================================
+ Hits         4091     4282     +191     
- Misses       1835     1872      +37     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

This allows using external functions in datalog.

This makes it easy to provide custom logic without extending the spec for every use-case, at the expense of portability: behaviour is no longer guaranteed to be consistent cross languages, and some languages won’t be able to support it at all (for instance JS as of now).

Todo:
- stricter conversions from datalog
- feature-gating if possible

Open questions:
- enum index for the FFI variants (contiguous or not?)
- how to provide functions (right now, function pointers: prevent mutability and closing over arguments)
- how to provide arguments (right now, datalog::Term, so symbols have to be resolved, and functions returning strings have to register new symbols)
- using boxed functions instead of function pointers allow capturing the environment
- using builder terms instead of datalog terms remove the need for manual symbol management
Instead of storing strings directly in the ops, do as we do for everything else and use the symbol table.

This required duplicating `biscuit_parser::builder::Binary` and `Unary` in the `biscuit_auth::builder` module (which previously used the definitions from the `datalog` module directly). There is a lot of duplication between `biscuit_parser::builder` and `biscuit_auth::builder`, with a circular-ish dependency (biscuit_auth depends on biscuit parser, but code generated by the `ToTokens` impl blocks in biscuit parser depend on `biscuit_auth::builder`).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant